<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { GetAllStation } from '@/utils/api/dispatch/station'
import stationList from './components/stationList.vue'


const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        code: "",
        warehouseid: null,
        shelvesid: null,
        layer: null,
        row: null,
        length: null,
        width: null,
        height: null,
        bearing: null,
        status: 1,
        sort: null,
        note: "",
        prestaid: null,
        lochigh: 0,
        lifthigh: 0,
        liftside: 0,
        lrdistance: null,
        lrdistance2: null,
        vehicletype: "",
        attribute: "",
        auxiliary: "",
        // stationList: [],
    }),
    statusSelect: [],
    attributeSelect: [],
    rackselect: [],
    stationSelect: [],
    rotateList: [],
    agvModel: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);


const statusSelect = ref(props.statusSelect);
const rackselect = ref(props.rackselect);
const stationSelect = ref(props.stationSelect);
const prestaidList = ref([]);
const agvModel = ref(props.agvModel);
const attributeSelect = ref(props.attributeSelect);
const lrdistanceList = ref(props.lrdistanceList)


function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });

const rotationangleList = [
    {
        name: '左',
        code: 1
    }
    , {
        name: '右',
        code: 2
    }]
// const lrdistanceList = [0, 1.33]
onMounted(async () => {
    // console.log('props=>', props.formInline);

    // 货位前站点
    let { Content }: any = await GetAllStation({ status: 1, stationType: 0 })
    prestaidList.value = Content
})
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="100px">
        <el-row :gutter="30">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="编码" prop="code">
                    <el-input v-model="newFormInline.code" clearable placeholder="请输入编码" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="所属货架" prop="shelvesid">
                    <el-select v-model="newFormInline.shelvesid" placeholder="请选择所属货架" style="width:100%">
                        <el-option v-for="item in rackselect" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="所在层数" prop="layer">
                    <el-input-number v-model="newFormInline.layer" controls-position="right" placeholder="请输入所在层数" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="所在列数" prop="row">
                    <el-input-number v-model="newFormInline.row" controls-position="right" placeholder="请输入所在列数" />
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="长度" prop="length">
          <el-input-number v-model="newFormInline.length" controls-position="right" placeholder="请输入长度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="宽度" prop="width">
          <el-input-number v-model="newFormInline.width" controls-position="right" placeholder="请输入宽度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="高度" prop="height">
          <el-input-number v-model="newFormInline.height" controls-position="right" placeholder="请输入高度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="承重" prop="bearing">
          <el-input-number v-model="newFormInline.bearing" controls-position="right" placeholder="请输入承重" />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="进入高度" prop="lochigh">
                    <el-input-number v-model="newFormInline.lochigh" controls-position="right" placeholder="请输入进入高度" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="抬升高度" prop="lifthigh">
                    <el-input-number v-model="newFormInline.lifthigh" controls-position="right" placeholder="请输入抬升高度" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="取货补偿" prop="lrdistance">
                    <el-select v-model="newFormInline.lrdistance" allow-create filterable placeholder="请选择取货补偿"
                        style="width:100%">
                        <el-option v-for="item in lrdistanceList" :key="item.Id" :label="Number(item.Name)"
                            :value="Number(item.Name)" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="放货补偿" prop="lrdistance2">
                    <el-select v-model="newFormInline.lrdistance2" allow-create filterable placeholder="请选择放货补偿"
                        style="width:100%">
                        <el-option v-for="item in lrdistanceList" :key="item.Id" :label="Number(item.Name)"
                            :value="Number(item.Name)" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="前后距离" prop="liftside">
                    <el-input-number v-model="newFormInline.liftside" controls-position="right" placeholder="请输入前后距离" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="旋转方向" prop="rotationangle">
                    <!-- <el-input-number v-model="newFormInline.rotationangle" controls-position="right" placeholder="请输入旋转角度" /> -->
                    <el-select v-model="newFormInline.rotationangle" filterable placeholder="请选择旋转方向"
                        style="width:100%">
                        <el-option v-for="item in rotationangleList" :key="item.code" :label="item.name"
                            :value="item.code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="AGV型号" prop="vehicletype">
                    <el-select v-model="newFormInline.vehicletype" placeholder="请选择AGV型号" style="width:100%">
                        <el-option v-for="item in agvModel" :key="item.Code" :label="item.Name" :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="货位状态" prop="status">
                    <el-select v-model="newFormInline.status" placeholder="请选择货位状态" style="width:100%">
                        <el-option v-for="item in statusSelect" :key="item.value" :label="item.label"
                            :value="item.value" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="货位站点" prop="auxiliary">
                    <el-select v-model="newFormInline.auxiliary" filterable placeholder="请选择货位站点" style="width:100%">
                        <el-option v-for="item in stationSelect" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="货位前站点" prop="prestaid">
                    <el-select v-model="newFormInline.prestaid" filterable clearable placeholder="请选择货位前站点"
                        style="width:100%">
                        <el-option v-for="item in prestaidList" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="货位类型" prop="attribute">
                    <el-select v-model="newFormInline.attribute" filterable placeholder="请选择货位类型" style="width:100%">
                        <el-option v-for="item in attributeSelect" :key="item.Id" :label="item.Name"
                            :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="排序" prop="sort">
                    <el-input-number v-model="newFormInline.sort" controls-position="right" placeholder="请输入排序" />
                </el-form-item>
            </re-col>
            <!-- <re-col :value="24" :xs="24" :sm="24">
                <el-form-item label="货位列表" prop="stationList" style="font-weight: 700;" class="callbox">
                    <stationList :data="newFormInline.stationList" :stationSelect="stationSelect"></stationList>
                </el-form-item>
            </re-col> -->
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item label="备注" prop="note">
                    <el-input v-model="newFormInline.note" clearable placeholder="请输入备注" type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
